package com.guanganren.db.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.guanganren.db.dao.CatgDao;
import com.guanganren.db.entity.Catg;
import com.guanganren.db.entity.CatgHome;
import com.guanganren.db.entity.LeaveMsg;

public class CatgDaoImpl extends HibernateDaoSupport implements CatgDao{

	private static final Log log = LogFactory.getLog(CatgHome.class);

	@Override
	public ArrayList<Catg> getAllCatg() {
		log.debug("com.guanganren.db.dao.impl:CatgDaoImple.getAllCatg()-------------------------start-------");
		//Session ss =  this.getHibernateTemplate().createQuery;
		
		ArrayList list =  (ArrayList)this.getHibernateTemplate().loadAll(Catg.class);
		log.debug("com.guanganren.db.dao.impl:CatgDaoImple.getAllCatg()-------------------------end-------");
		return list;
	}

	@Override
	public List<Catg> getCatgByParentId(String id) throws Exception {
		List<Catg> list=null;
		try{
			String queryString = "from com.guanganren.db.entity.Catg c where c.catg.catgId=?";
			list = this.getHibernateTemplate().find(queryString,new Integer(id));
		}catch(Exception ex){
			throw new Exception();
		}
		return list;
	}

	@Override
	public Catg getCatg(String id) throws Exception {
		Catg catg=null;
		try{
			//String queryString = "from com.guanganren.db.entity.Catg c where c.catg_id=?";
			catg = this.getHibernateTemplate().get(Catg.class,new Integer(id));
		}catch(Exception ex){
			throw new Exception();
		}
		return catg;
	}

}
